$(function(){
    uri=$('#login_button').attr("data");
    $('#login_button').click(function(){
        frontValidate();
    });
    freeseven();
    //doLogin("","",true);
})
/*登录相关*/
function frontValidate(){
    var username=$('#user_name');
    var password=$('#user_pas');
    var name=username.val();
    var pwd=password.val();
    clearMessage();
    if(!checkuser(name))
    {
        return;
    }
    if(!checkpas(pwd))
    {
        return;
    }
    doLogin(name,pwd,false);

}
function checkuser(tel){
    console.log(tel);
    var userreg = /^1[0-9]{10}$/;
    var emailreg = /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    if (userreg.test(tel) || emailreg.test(tel))
    {
        return true;
    }else{
        //失败
        //$('#user_name_message').html("请输入有效的用户名或手机号或邮箱");
        //$('#user_name_message').show();
        $('#login_message').html("请输入有效的用户名或手机号或邮箱");
    }

    return false;

}
function checkpas(val){
    console.log(val);
    var reg = /^[a-zA-Z0-9]{6,16}$/;
    if(reg.test(val)){
        return true;
    }else{
        //失败
        //$('#user_pas_message').html("请输入有效的6-16位密码");
        //$('#user_pas_message').show();
        $('#login_message').html("请输入有效的6-16位密码");
        return;
    }
    return false;
}
function clearMessage(){
    $('#user_name_message').hide();
    $('#user_pas_message').hide();
    $('#login_message').html('');
}
var isRem=false;
function freeseven(){
    $('#J-m-isSeven').click(function(){
        var flag=$(this).attr("data-isseven");
        if(flag==0){
            //改变为激活
            $(this).attr("class","selected_icon");
            $(this).attr("data-isseven",1);
            isRem=true;
        }else{
            $(this).attr("class","unselected_icon");
            $(this).attr("data-isseven",0);
            isRem=false;
        }
    });
    return isRem;
}
var url_='http://'+window.location.host;
var uri='1';
function doLogin(name,pwd,isValidate){
    if(uri!='1'&& uri!=null && uri!=undefined){

    }else{
        uri=GetQueryString('uri');
    }
    if(uri==null || uri=='' || uri==undefined){
        uri='/index';
    }
    console.log('----------------------'+uri);
    $.post("/login/dologin",{"mobile":name,"password":pwd,"isRember":isRem?1:0,'isValidate':isValidate,'uri':uri,"time":new Date()},function(json){
        console.log("login data-----"+json.code+json.message+json.data);
        if(json.code!=200){
            $('#login_message').html(json.message);
        }else{
            window.location.href=url_+uri;
        }
    });
}